package Dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class FactoryProxy  {
    private Object target;

    public FactoryProxy(Object target){
        this.target = target;
    }

    public Object getProxyIstance() {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理前");
                Object returnVal = method.invoke(target,args);
                System.out.println("代理后");

                return returnVal;

            }
        });
    };
}
